//
//  MCMineHeaderView.m
//  TLYL
//
//  Created by MC on 2017/6/12.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMineHeaderView.h"
#import "MCMineHeaderFooterView.h"

@interface MCMineHeaderView()
@property (nonatomic,strong)UIImageView * imgV_UserIcon;//用户头像
@property (nonatomic,strong)UILabel * lab_UserName;//用户名
@property (nonatomic,strong)UILabel *lab_accountBalance;//账户余额
@property (nonatomic,strong)UILabel *lab_accountBalanceNumber;//账户余额 （数字）
@property (nonatomic,strong)UILabel *lab_frozenAccount;//冻结金额
@property (nonatomic,strong)UILabel *lab_frozenAccountNumber;//冻结金额 （数字）
@property (nonatomic,strong)MCMineHeaderFooterView * view_Footer;
@property (nonatomic,strong)UIView * view_back;
@end

@implementation MCMineHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    
    
    self.backgroundColor=RGB(239, 246, 253);
    _view_back=[[UIView alloc]init];
    [self addSubview:_view_back];
    _view_back.backgroundColor=RGB(52, 156, 247);

    
    /**
     * 设置按钮
     **/
    _imgV_setting=[[UIImageView alloc]init];
    [_view_back addSubview:_imgV_setting];
    _imgV_setting.userInteractionEnabled=YES;
    _imgV_setting.image=[UIImage imageNamed:@"MC_My_Setting"];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_setting)];
    [_imgV_setting addGestureRecognizer:tap];
    
    /*
     * 用户头像
     */
    _imgV_UserIcon=[[UIImageView alloc]init];
    [_view_back addSubview:_imgV_UserIcon];
    _imgV_UserIcon.userInteractionEnabled=YES;
    _imgV_UserIcon.image=[UIImage imageNamed:@"fc_sd"];

    
    /*
     * 用户名
     */
    _lab_UserName=[[UILabel alloc]init];
    _lab_UserName.font = [UIFont systemFontOfSize:12];
    _lab_UserName.numberOfLines=1;
    _lab_UserName.text = @"加载中...";
    _lab_UserName.textColor=[UIColor whiteColor];
    _lab_UserName.textAlignment=NSTextAlignmentCenter;
    [_view_back addSubview:_lab_UserName];


    
    

    /*
     * 账户余额
     */
    _lab_accountBalance=[[UILabel alloc]init];
    _lab_accountBalance.font = [UIFont systemFontOfSize:15];
    _lab_accountBalance.numberOfLines=1;
    _lab_accountBalance.textColor=[UIColor whiteColor];
    _lab_accountBalance.text = @"账户余额";
    _lab_accountBalance.textAlignment=NSTextAlignmentCenter;
    [_view_back addSubview:_lab_accountBalance];

    
    
    /*
     * 账户余额 （数字）
     */
    _lab_accountBalanceNumber=[[UILabel alloc]init];
    _lab_accountBalanceNumber.font = [UIFont systemFontOfSize:13];
    _lab_accountBalanceNumber.numberOfLines=1;
    _lab_accountBalanceNumber.textColor=[UIColor whiteColor];
    _lab_accountBalanceNumber.text = @"1000";
    _lab_accountBalanceNumber.textAlignment=NSTextAlignmentCenter;
    [_view_back addSubview:_lab_accountBalanceNumber];

    
    
    /*
     * 冻结金额
     */
    _lab_frozenAccount=[[UILabel alloc]init];
    _lab_frozenAccount.font = [UIFont systemFontOfSize:15];
    _lab_frozenAccount.numberOfLines=1;
    _lab_frozenAccount.text = @"冻结余额";
    _lab_frozenAccount.textColor=[UIColor whiteColor];
    _lab_frozenAccount.textAlignment=NSTextAlignmentCenter;
    [_view_back addSubview:_lab_frozenAccount];

    
    /*
     * 冻结金额 （数字）
     */
    _lab_frozenAccountNumber=[[UILabel alloc]init];
    _lab_frozenAccountNumber.font = [UIFont systemFontOfSize:13];
    _lab_frozenAccountNumber.numberOfLines=1;
    _lab_frozenAccountNumber.textColor=[UIColor whiteColor];
    _lab_frozenAccountNumber.text = @"9999";
    _lab_frozenAccountNumber.textAlignment=NSTextAlignmentCenter;
    [_view_back addSubview:_lab_frozenAccountNumber];

    
    
    
    _view_Footer=[[MCMineHeaderFooterView alloc]init];
    [self addSubview:_view_Footer];
    [_view_Footer.btn_recharge addTarget:self action:@selector(action_recharge) forControlEvents:UIControlEventTouchUpInside];
    [_view_Footer.btn_withdraw addTarget:self action:@selector(action_withdraw) forControlEvents:UIControlEventTouchUpInside];
    [_view_Footer.btn_message addTarget:self action:@selector(action_message) forControlEvents:UIControlEventTouchUpInside];

    
    [self layOutConstraints];
    
}

-(void)layOutConstraints{
    CGFloat WIDTH=[self  getWidthWithTitle:@"冻结余额" font:15];

    [_view_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(-25);
    }];
    /**
     * 设置按钮
     **/

    [_imgV_setting mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_back.mas_top).offset(20);
        make.right.equalTo(_view_back.mas_right).offset(-10);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];

    
    /*
     * 用户头像
     */

    [_imgV_UserIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_back.mas_top).offset(40);
        make.centerX.equalTo(_view_back.mas_centerX);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    
    /*
     * 用户名
     */

    [_lab_UserName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_view_back.mas_centerX);
        make.top.equalTo(_imgV_UserIcon.mas_bottom).offset(10);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(220);
    }];
    
    
    
    
    /*
     * 账户余额
     */

    [_lab_accountBalance mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_imgV_UserIcon.mas_left).offset(-20);
        make.top.equalTo(_imgV_UserIcon.mas_bottom).offset(-15);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(WIDTH);
    }];
    
    
    /*
     * 账户余额 （数字）
     */

    [_lab_accountBalanceNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_lab_accountBalance.mas_centerX);
        make.top.equalTo(_lab_accountBalance.mas_bottom).offset(0);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(G_SCREENWIDTH);
    }];
    
    
    /*
     * 冻结金额
     */
   
    [_lab_frozenAccount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imgV_UserIcon.mas_right).offset(20);
        make.top.equalTo(_imgV_UserIcon.mas_bottom).offset(-15);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(WIDTH);
    }];
    
    /*
     * 冻结金额 （数字）
     */
 
    [_lab_frozenAccountNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_lab_frozenAccount.mas_centerX);
        make.top.equalTo(_lab_frozenAccount.mas_bottom).offset(0);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(G_SCREENWIDTH);
    }];
    
    

    [_view_Footer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom);
        make.left.equalTo(self.mas_left).offset(50);
        make.right.equalTo(self.mas_right).offset(-50);
        make.height.mas_equalTo(50);
    }];
    
    
}

/**
 *   获取字符宽度
 */
- (CGFloat)getWidthWithTitle:(NSString *)title font:(CGFloat )font {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
    label.text = title;
    label.font = [UIFont systemFontOfSize:font];
    [label sizeToFit];
    return label.frame.size.width;
}
-(void)setDataSource:(id)dataSource{
    _dataSource=dataSource;
    _lab_UserName.text = @"Simone";
    _lab_accountBalanceNumber.text = @"1000";
    _lab_frozenAccountNumber.text = @"9999";
}

/*
 * 跳转设置
 */
-(void)action_setting{
    if ([self.delegate respondsToSelector:@selector(MCMineHeaderView_Setting)]) {
        [self.delegate MCMineHeaderView_Setting];
    }
}

/*
 * 跳转充值
 */
-(void)action_recharge{
    if ([self.delegate respondsToSelector:@selector(MCMineHeaderView_Recharge)]) {
        [self.delegate MCMineHeaderView_Recharge];
    }
}

/*
 * 跳转提现
 */
-(void)action_withdraw{
    if ([self.delegate respondsToSelector:@selector(MCMineHeaderView_Withdraw)]) {
        [self.delegate MCMineHeaderView_Withdraw];
    }
}

/*
 * 跳转站内信
 */
-(void)action_message{
    if ([self.delegate respondsToSelector:@selector(MCMineHeaderView_Message)]) {
        [self.delegate MCMineHeaderView_Message];
    }
}



@end













































